<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>createRef 表示方式</title>
    <style>
        #result{
            width: 400px;height: 300px;
            border:solid 1px #231;
        }
    </style>
</head>
<body>
    <div id="root"> </div>

    <script src="../js/react.development.js"></script>
    <script src="../js/react-dom.development.js"></script>
    <script src="../js/babel.min.js"></script>

    <script type="text/babel">
        class App extends React.Component {
            // 1. 创建一个属性. 为实例对象添加属性 input 
            input = React.createRef();
            div = React.createRef();
            render(){
                return <div>
                        {/*2. ref 属性值中设置该属性*/}
                        <input type="text" ref={this.input} />  <button onClick={this.show}>显示</button>
                        <hr />
                        <div id="result" ref={this.div}>
                            
                        </div>
                    </div>
            }

            show = () => {
                //3. 获取 input 元素
                let input = this.input.current;
                //获取元素的值
                let v = input.value;
                //获取
                let div = this.div.current;
                //设置
                div.innerHTML = v;
            }
        }

        ReactDOM.render(<App />, document.querySelector("#root"));
    </script>
</body>
</html>